<?php
if (!defined("_INDEX")) { header("Location: /"); die; }

if ($user->getCoordinatorType() == 1)
{
	$reports = $db->getCell("select count(`report_id`) from `reports` where `user_id` = '".$user->getUserId()."'");
	$joinedReports = $db->getColumn("select `J`.`joined_id` from `joined` as `J`,`reports` as `R` where `J`.`report_id` = `R`.`report_id` and `R`.`user_id` = '".$user->getUserId()."'");
}
else
{
	$reports = $db->getCell("select count(`report_id`) from `reports` where `user_id` = '".$user->getUserId()."'");
	$friendsReports = $db->getColumn("select `F`.`friend_id` from `friends` as `F`,`reports` as `R` where `F`.`report_id` = `R`.`report_id` and `R`.`user_id` = '".$user->getUserId()."'");
	$commentsReports = $db->getColumn("select `C`.`comment_id` from `comments` as `C`,`reports` as `R` where `C`.`report_id` = `R`.`report_id` and `R`.`user_id` = '".$user->getUserId()."'");
	$topicsReports = $db->getColumn ("select `T`.`topic_id` from `topics` as `T`,`reports` as `R` where `T`.`report_id` = `R`.`report_id` and `R`.`user_id` = '".$user->getUserId()."'");
}

require_once COORDINATOR.DS."head.php";
?>
<script type='text/javascript'>
$(document).ready(function(){
	$("#getLink").click(function(){
		if ($("#rText").val() != "")
		{
			var link_address = "http://smelvzor.org/registration?rid="+$("#rid").val();
			var link_code = "<a href=\""+link_address+"\">"+$("#rText").val()+"</a>";
			$("#link_code").val(link_code);
			$("#link_address").val(link_address);
		}
		else
			$("#rText").focus();
	})
})
</script>
<style> .bold { font-weight: bold } </style>
<div>
	<h3>Реферальная ссылка</h3><br />
	<input type='hidden' id="rid" value="<?php echo md5($user->getUserId()); ?>" />
	<label for="rText">Текст ссылки</label><br />
	<input type='text' id='rText' style="width:400px;" class='rBorder' value="Смелый взор" /><br />
	<table cellpadding='10' cellspacing='0' style="margin:10px 0">
		<tr>
			<td width='410px'><label for="link_code">Код ссылки</label></td>
			<td><label for="link_address">Адрес ссылки</label></td>
		</tr>
		<tr>
			<td><textarea id='link_code' class='rBorder' style="width:400px; height:80px;margin:5px 0;"></textarea></td>
			<td><textarea id='link_address' class='rBorder' style="width:400px; height:80px;margin:5px 0;"></textarea></td>
		</tr>
	</table>
	<input type='button' id='getLink' value="Получить ссылку" style="padding: 3px 15px" /><br /><br />
</div>
<h3>Статистика</h3><br />
<?php
if ($user->getCoordinatorType() == 1)
{
	echo "<p>Всего отчетов: ".$reports."</p><br />";
	echo "<p>Приглашенных пользователей: ".count($joinedReports)."</p>";
}
else
{
	echo "<p>Всего отчетов: ".$reports."</p><br />";
	echo "<p>Друзей: ".count($friendsReports)."</p>";
	echo "<p>Комментариев: ".count($commentsReports)."</p>";
	echo "<p>Статей: ".count($topicsReports)."</p>";
}

require_once COORDINATOR.DS."footer.php"; ?>